package com.khshop.vo;

import java.util.HashMap;


public class AjaxResult extends HashMap<String, Object> {
    public static final int ERROR = 500, SUCCESS = 0;
    private static final long serialVersionUID = 1L;


    public static final String CODE_TAG = "code";

    public static final String MSG_TAG = "msg";

    public static final String DATA_COUNT = "count";

    public static final String DATA_TAG = "data";





    public AjaxResult() {
    }

    public AjaxResult(int code, String msg) {
        super.put(CODE_TAG, code);
        super.put(MSG_TAG, msg);
    }

    public AjaxResult(int code, String msg, Object data) {
        super.put(CODE_TAG, code);
        super.put(MSG_TAG, msg);
        if (data != null) {
            super.put(DATA_TAG, data);
        }
    }

    public AjaxResult(int code, String msg, int count,Object data) {
        super.put(CODE_TAG, code);
        super.put(MSG_TAG, msg);
        super.put(DATA_COUNT, count);
        if (data != null) {
            super.put(DATA_TAG, data);
        }
    }

    public static AjaxResult success() {
        return AjaxResult.success("操作成功");
    }

    public static AjaxResult success(Object data) {
        return AjaxResult.success("执行成功", data);
    }

    public static AjaxResult success(String msg) {
        return AjaxResult.success(msg, null);
    }

    public static AjaxResult success(String msg, Object data) {
        return new AjaxResult(SUCCESS, msg, data);
    }

    public static AjaxResult success(int count,Object data) {
        return new AjaxResult(SUCCESS, "执行成功",count, data);
    }

    public static AjaxResult success(String msg, int count,Object data) {
        return new AjaxResult(SUCCESS, msg,count, data);
    }



    public static AjaxResult error() {
        return AjaxResult.error("出现错误");
    }

    public static AjaxResult error(String msg) {
        return AjaxResult.error(msg, null);
    }

    public static AjaxResult error(String msg, Object data) {
        return new AjaxResult(ERROR, msg, data);
    }

    public static AjaxResult error(int code, String msg) {
        return new AjaxResult(code, msg, null);
    }

    public static AjaxResult error(int code, int count,String msg) { return new AjaxResult(code, msg, count, null); }
}